﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;

//引用实体层
using WebeTerm.Model;
using WebeTerm.Common;
#endregion

namespace WebeTerm.DbProvider{
    /// <summary>
    /// 文 件 名: CompanyMailSMTPDAL.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: 公司发邮件服务配置
    /// 生成日期: 2014年12月5日
    /// </summary>
    public partial class CompanyMailSMTPDAL:BaseDAL< CompanyMailSMTP >{
        
        #region 通用查询
        /// <summary>
        /// 查询系统设置
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="pages">分页信息</param>
        /// <returns>系统设置</returns>
        public List< CompanyMailSMTP > SearchCompanyMailSMTP(CompanyMailSMTPQuery queryParam, Pages pages)
        {
            IQueryable< CompanyMailSMTP > iQuery = QueryCompanyMailSMTP(queryParam);
            var items = base.SplitPage(iQuery, pages).ToList();
            items.ForEach(l=>{
                { if (l is IModel) { (l as IModel).SetIsLoaded(); } }    
            });
            return items;
        }

        /// <summary>
        /// 计算系统设置数
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>系统设置数</returns>
        public int SearchCompanyMailSMTPCount(CompanyMailSMTPQuery queryParam)
        {
            return QueryCompanyMailSMTP(queryParam).Count();
        } 
        #endregion

        #region 组合查询
        /// <summary>
        /// 设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>公司发邮件服务配置</returns>
        public IQueryable< CompanyMailSMTP > QueryCompanyMailSMTP(CompanyMailSMTPQuery queryParam)
        {
            IQueryable<CompanyMailSMTP> iQuery = All();
            iQuery = QueryCompanyMailSMTPById(queryParam, iQuery);
            iQuery = QueryCompanyMailSMTPByServerAddress(queryParam, iQuery);
            iQuery = QueryCompanyMailSMTPByServerPort(queryParam, iQuery);
            iQuery = QueryCompanyMailSMTPBySMTPAccount(queryParam, iQuery);
            iQuery = QueryCompanyMailSMTPBySMTPassword(queryParam, iQuery);
            iQuery = QueryCompanyMailSMTPByIsValid(queryParam, iQuery);
            iQuery = QueryCompanyMailSMTPByCompanyId(queryParam, iQuery);
            return iQuery;
        }
        #endregion
        
        #region 单条件查询
        /// <summary>
        /// 根据设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司发邮件服务配置 查询</param>
        /// <returns>公司发邮件服务配置 查询</returns>
        protected virtual IQueryable< CompanyMailSMTP > QueryCompanyMailSMTPById(CompanyMailSMTPQuery queryParam, IQueryable< CompanyMailSMTP > iQuery)
        {
            if (queryParam.Id != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.Id == queryParam.Id);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司发邮件服务配置 查询</param>
        /// <returns>公司发邮件服务配置 查询</returns>
        protected virtual IQueryable< CompanyMailSMTP > QueryCompanyMailSMTPByServerAddress(CompanyMailSMTPQuery queryParam, IQueryable< CompanyMailSMTP > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.ServerAddress))
                iQuery = iQuery.Where(iq => iq.ServerAddress.Contains(queryParam.ServerAddress.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司发邮件服务配置 查询</param>
        /// <returns>公司发邮件服务配置 查询</returns>
        protected virtual IQueryable< CompanyMailSMTP > QueryCompanyMailSMTPByServerPort(CompanyMailSMTPQuery queryParam, IQueryable< CompanyMailSMTP > iQuery)
        {
            if (queryParam.ServerPort != (int)0)
                iQuery = iQuery.Where(iq => iq.ServerPort == queryParam.ServerPort);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司发邮件服务配置 查询</param>
        /// <returns>公司发邮件服务配置 查询</returns>
        protected virtual IQueryable< CompanyMailSMTP > QueryCompanyMailSMTPBySMTPAccount(CompanyMailSMTPQuery queryParam, IQueryable< CompanyMailSMTP > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.SMTPAccount))
                iQuery = iQuery.Where(iq => iq.SMTPAccount.Contains(queryParam.SMTPAccount.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司发邮件服务配置 查询</param>
        /// <returns>公司发邮件服务配置 查询</returns>
        protected virtual IQueryable< CompanyMailSMTP > QueryCompanyMailSMTPBySMTPassword(CompanyMailSMTPQuery queryParam, IQueryable< CompanyMailSMTP > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.SMTPassword))
                iQuery = iQuery.Where(iq => iq.SMTPassword.Contains(queryParam.SMTPassword.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司发邮件服务配置 查询</param>
        /// <returns>公司发邮件服务配置 查询</returns>
        protected virtual IQueryable< CompanyMailSMTP > QueryCompanyMailSMTPByIsValid(CompanyMailSMTPQuery queryParam, IQueryable< CompanyMailSMTP > iQuery)
        {
            if (queryParam.IsValid != false)
                iQuery = iQuery.Where(iq => iq.IsValid == queryParam.IsValid);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司发邮件服务配置 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司发邮件服务配置 查询</param>
        /// <returns>公司发邮件服务配置 查询</returns>
        protected virtual IQueryable< CompanyMailSMTP > QueryCompanyMailSMTPByCompanyId(CompanyMailSMTPQuery queryParam, IQueryable< CompanyMailSMTP > iQuery)
        {
            if (queryParam.CompanyId != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.CompanyId == queryParam.CompanyId);
            return iQuery;
        }
        #endregion
    }
}    